//
//  YGPreHeaderView.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/5/1.
//

#import "YGPreHeaderView.h"

@interface YGPreHeaderView ()
@property (nonatomic, strong) UIButton  *selectRecBtn;
@property (nonatomic, strong) UIButton  *iconBtn;

@end
@implementation YGPreHeaderView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initView];
        [self.selectRecBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.height.mas_equalTo(20);
            make.width.mas_equalTo(100);
            make.centerY.mas_equalTo(self.mas_centerY);
        }];
        
        [self.iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(14);
            make.right.mas_equalTo(self).offset(-10);
            make.centerY.mas_equalTo(self.mas_centerY);
        }];
    }
    return self;
}

- (void)initView{
    [self addSubview:self.selectRecBtn];
    [self addSubview:self.iconBtn];
}

- (void)setSelect:(BOOL)select{
    self.selectRecBtn.selected = select;
    self.iconBtn.selected = select;
}

- (void)clickSelectAction{
    [self setSelect:!self.selectRecBtn.selected];
    
    if (self.ClickBlock) {
        self.ClickBlock(self.tag);
    }
}

- (UIButton *)selectRecBtn
{
    if(!_selectRecBtn){
        _selectRecBtn = [[UIButton alloc] init];
        [_selectRecBtn setTitle:@"处方建议" forState:UIControlStateNormal];
        [_selectRecBtn setImage:[UIImage imageNamed:@"gender_btn_icon"] forState:UIControlStateNormal];
        _selectRecBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_selectRecBtn setImage:[UIImage imageNamed:@"gender_selected_btn_icon"] forState:UIControlStateSelected];
        [_selectRecBtn setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
        [_selectRecBtn addTarget:self action:@selector(clickSelectAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectRecBtn;
}

- (UIButton *)iconBtn
{
    if(!_iconBtn){
        _iconBtn = [[UIButton alloc] init];
        [_iconBtn setImage:[UIImage imageNamed:@"food_right"] forState:UIControlStateNormal];
        [_iconBtn setImage:[UIImage imageNamed:@"food_down"] forState:UIControlStateSelected];
        _iconBtn.enabled = NO;
    }
    return _iconBtn;
}

@end
